const mongodb = require("./mongodb");
const co = require("co");
const log4js = require("log4js"),
    log = log4js.getLogger("main");
const thunkify = require("thunkify");

const app = require('./app');
const http = require('http');

const port = 3200;
function* init() {
    try {
        log4js.configure({
            appenders: {
                out: { type: 'stdout' }
            },
            categories: {
                default: { appenders: ['out'], level: 'debug' }
            }
        });
        var nf = thunkify(mongodb.init);
        let r = yield nf("mongodb://127.0.0.1/sch");
        log.info("mongodb connected ok");

        //web
        var server = http.createServer(app);
        server.listen(port);
    } catch (exception) {
        log.error(exception)
        process.exit(0);
    }
}
co(init)